package com.tarena.lbs.business.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.business.dao.mapper.BusinessCategoryMapper;
import com.tarena.lbs.business.dao.repository.BusinessCategoryRepository;
import com.tarena.lbs.business.pojo.po.BusinessCategoryPO;
import com.tarena.lbs.business.pojo.vo.BusinessCategoryVO;
import istio.v1.auth.Ca;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Repository
public class BusinessCategoryRepositoryImpl implements BusinessCategoryRepository {
    @Autowired
    private BusinessCategoryMapper businessCategoryMapper;
    @Override
    public List<BusinessCategoryVO> selectCategory() {
        // 1. 构建查询条件（查询 PO 类）
        QueryWrapper<BusinessCategoryPO> queryWrapper = new QueryWrapper<>();
        // 只查询需要的字段（PO 类中的字段名）
        queryWrapper.select("id", "label", "sort", "status", "remark", "create_time", "update_time");

        // 2. 查询 PO 列表（返回的是 BusinessCategoryPO 类型）
        List<BusinessCategoryPO> poList = businessCategoryMapper.selectList(queryWrapper);

        // 3. 将 PO 列表通过 Stream 转换为 VO 列表
        List<BusinessCategoryVO> voList = poList.stream()
                        .map(po -> {
                            BusinessCategoryVO vo = new BusinessCategoryVO();
                            // 复制 PO 的属性到 VO（忽略不存在的属性）
                            BeanUtils.copyProperties(po, vo);
                            return vo;
                        })
                        .collect(Collectors.toList());
        return voList;
    }
}
